package com.sxl.main;

import cn.hutool.crypto.SecureUtil;
import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.Map;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) throws IOException {
        Map<String, String> map = new TreeMap<>();
        map.put("sid", "java_dev");
        map.put("appName", "huijingying");
        map.put("timestamp","1657018231" );
        String body = "{\r\n" +
                "    \"id_list\":[],\r\n" +
                "    \"sku_list\":[],\r\n" +
                "    \"page_size\":100,\r\n" +
                "    \"page_no\":1,\r\n" +
                "    \"start_time\":\"2022-05-30 11:09:57\",\r\n" +
                "    \"end_time\":\"2022-06-30 11:09:57\",\r\n" +
                "    \"status\":1\r\n" +
                "}";
        map.put("body",body);
        String sb ="3f31fd4211d16a84sdax73wwe97r7d10appNamesymybody{\"pageNo\":1,\"pageSize\":200,\"start_time\":\"2023-09-01 00:00:00\",\"end_time\":\"2023-09-30 23:59:59\",\"status\":0}sidsymytimestamp17024582783f31fd4211d16a84sdax73wwe97r7d10";
        String sign =SecureUtil.md5(sb);

        System.out.println(sign);

//        660619fd62d86fb07c53d166fa1a840f


    }
    private static String linkParams(Map<String, String> map,String secret) {
        StringBuilder sb = new StringBuilder();
        sb.append(secret);
        for (Map.Entry<String, String> item : map.entrySet())
        {
            if (item.getKey().equals("sign"))
                continue;
            sb.append(item.getKey());
            sb.append(item.getValue());
        }
        sb.append(secret);
        return  sb.toString();
    }
    public static String addBinary(String a, String b) {
        if(a==null||a.length()==0){
            return b;
        }else if(b==null||b.length()==0){
            return a;
        }
        StringBuilder sb = new StringBuilder();
        byte[] list1 = a.getBytes();
        byte[] list2 = b.getBytes();
        for (int i = 0; i < list1.length; i++) {
            list1[i]-=48;
        }
        for (int i = 0; i < list2.length; i++) {
            list2[i]-=48;
        }
        //补0
        if(a.length()>b.length()){
            byte[] temp =  new byte[a.length()];
            System.arraycopy(list2,0,temp,a.length()-b.length(),b.length());
            list2 = temp;
        }else {
            byte[] temp =  new byte[b.length()];
            System.arraycopy(list1,0,temp,b.length()-a.length(),a.length());
            list1 = temp;
        }
        int n = 0;
        for (int i = list1.length - 1; i >= 0; i--) {
            n = list1[i]+list2[i]+n;
            sb.append(n%2);
            n = n/2;
        }
        if(n > 0){
            sb.append(n);
        }
        return sb.reverse().toString();
    }

    /**
     * 下载文件---返回下载后的文件存储路径
     *
     * @param url 文件地址
     * @param dir 存储目录
     * @param fileName 存储文件名
     * @return
     */
    public static void downloadHttpUrl(String url, String dir, String fileName) throws IOException {
        URL httpurl = new URL(url);
        File dirfile = new File(dir);
        if (!dirfile.exists()) {
            dirfile.mkdirs();
        }
        FileUtils.copyURLToFile(httpurl, new File(dir+fileName));
    }



}
